using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using FiltronASP.Models.DAO;
using FiltronASP.Models;
using FiltronASP.Models.DAO.Filtron;
using FiltronASP.Models.DAO.Interfaces.Filtron;
using FiltronASP.Helpers.Translations;
using System.Text;

namespace FiltronASP.Helpers.AjaxModel
{
    public static class EngineTableHelper
    {
        public static string generateEngineTable(int modelId, string languageName) {
            if (modelId.Equals(0))
            {
                return null;
            }
            if (languageName == "")
            {
                return null;
            }

            string toReturn = String.Empty;
            IFiltronEngineDAO filtronEngineDAO = new FiltronEngineDAO();
            IQueryable<FiltronEngine> filtronEngines = filtronEngineDAO.FindByModel(modelId);

            StringBuilder sb = new StringBuilder();
            //naglowek
            sb.Append("<div class='col-xs-12 no-padding overlay-engine overlay-engine-boder-b'>");
            sb.Append("<div class='col-xs-6 no-padding'>");
            sb.Append("<div class='col-xs-7 no-padding overlay-engine-boder-r'>");
            sb.Append("<p>" + translationHelper.getTranslation("_hlpEngine", languageName) + "</p>");
            sb.Append("</div>");
            sb.Append("<div class='col-xs-5 no-padding overlay-engine-boder-r'>");
            sb.Append("<p >" + translationHelper.getTranslation("_hlpEngineCC", languageName) + "</p>");
            sb.Append(String.Format("<img class='img-responsive' src='{0}' alt='cc'>", VirtualPathUtility.ToAbsolute("~/Content/img/engine1.png")));
            sb.Append("</div>");
            sb.Append("</div>");
            sb.Append("<div class='col-xs-6 no-padding'>");
            sb.Append("<div class='col-xs-6 no-padding overlay-engine-boder-r'>");
            sb.Append("<p >" + translationHelper.getTranslation("_hlpEngineNo", languageName) + "</p>");
            sb.Append(String.Format("<img class='img-responsive' src='{0}' alt='cc'>", VirtualPathUtility.ToAbsolute("~/Content/img/aa.png")));
            sb.Append("</div>");
            sb.Append("<div class='col-xs-6 no-padding'>");
            sb.Append("<p>" + translationHelper.getTranslation("_hlpEngineHP", languageName) + "</p>");
            sb.Append(String.Format("<img class='img-responsive' src='{0}' alt='cc'>", VirtualPathUtility.ToAbsolute("~/Content/img/hp.png")));
            sb.Append("</div>");
            sb.Append("</div>");
            sb.Append("</div>");
            //wiersze
            if (filtronEngines != null)
            {
                foreach (var filtronEngine in filtronEngines)
                {
                    sb.Append(String.Format("<div class='col-xs-12 no-padding overlay-engine engine-hover overlay-engine-boder-b engine-selector' data-model='{0}' data-engine='{1}'>", modelId, filtronEngine.engine_id));
                    sb.Append("<div class='col-xs-6 no-padding engine-height'>");
                    sb.Append("<div class='col-xs-7 no-padding overlay-engine-boder-r'>");
                    if (filtronEngine.engine_description != null)
                    {
                        sb.Append(String.Format("<p class='engine-info-bold'>{0}<br/>{1}</p>", filtronEngine.engine_name, filtronEngine.engine_description.TrimEnd(' ', ';')));
                    }   //if
                    else
                    {
                        sb.Append(String.Format("<p class='engine-info-bold'>{0}</p>", filtronEngine.engine_name));
                    }   //else
                    sb.Append("</div>");
                    sb.Append("<div class='col-xs-5 no-padding overlay-engine-boder-r no-hp-100'>");
                    sb.Append(String.Format("<p  class='engine-info-normal'>{0}</p>", filtronEngine.engine_cubic_capacity));
                    sb.Append("</div>");
                    sb.Append("</div>");
                    sb.Append("<div class='col-xs-6 no-padding no-hp-100'>");
                    sb.Append("<div class='col-xs-6 no-padding overlay-engine-boder-r height-100 eng-numb-over'>");
                    sb.Append(String.Format("<p class='engine-info-normal eng-numb'>{0}</p>", filtronEngine.engine_code));
                    sb.Append("</div>");
                    sb.Append("<div class='col-xs-6 no-padding height-100'>");
                    sb.Append(String.Format("<p class='engine-info-normal'>{0}</p>", filtronEngine.engine_horse_power));
                    sb.Append("</div>");
                    sb.Append("</div>");
                    sb.Append("</div>");
                }   //foreach
            }   //if not null
            return sb.ToString();
        }
    }
}
